﻿Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media.Animation


Public Class Ship
    Inherits Sprite
    Private _MaxX As Double
    Public Property MaxX() As Double
        Get
            Return _MaxX
        End Get
        Set(ByVal value As Double)
            _MaxX = value
        End Set
    End Property
    Private _MinX As Double
    Public Property MinX() As Double
        Get
            Return _MinX
        End Get
        Set(ByVal value As Double)
            _MinX = value
        End Set
    End Property
    Private _FadeStoryboard As Storyboard
    Public Property FadeStoryboard() As Storyboard
        Get
            Return _FadeStoryboard
        End Get
        Set(ByVal value As Storyboard)
            _FadeStoryboard = value
        End Set
    End Property

    Public Sub New(ByVal width As Double, ByVal height As Double, ByVal firstPosition As Point)
        MyBase.New(width, height, firstPosition)
        FadeStoryboard = New Storyboard()
        Dim durationTimeline As New Duration(TimeSpan.FromMilliseconds(2000))
        Dim spawnFade As New DoubleAnimation()

        spawnFade.From = 0.1
        spawnFade.[To] = 1
        spawnFade.SetValue(Storyboard.TargetNameProperty, SpriteCanvas.Name)
        spawnFade.SetValue(Storyboard.TargetPropertyProperty, New PropertyPath("Opacity"))
        spawnFade.Duration = durationTimeline
        FadeStoryboard.Children.Add(spawnFade)
        SpriteCanvas.Resources.Add("SpawnFadeAnimation", FadeStoryboard)
        FadeStoryboard.Begin()
    End Sub

    Public Overloads Overrides Function RenderSpriteCanvas() As Canvas
        Return LoadSpriteCanvas("SimpleShooter.Ship.xaml")
    End Function

    Public Overloads Overrides Sub Update(ByVal elapsedTime As System.TimeSpan)
        'verify that this is a position we can move to 
        If Position.X > MaxX Then
            Position = New Point(MaxX, Position.Y)
            Velocity = New Vector(0, 0)
        End If
        If Position.X < MinX Then
            Position = New Point(MinX, Position.Y)
            Velocity = New Vector(0, 0)
        End If
        MyBase.Update(elapsedTime)
    End Sub

    Public Function Fire() As Missle
        Dim missle As New Missle(5, 5, Position)
        missle.Velocity = Vector.CreateVectorFromAngle(0, 250)
        Return missle
    End Function
End Class
